'use strict';
var logger = require('koa-logger');
var router = require('koa-router');
var serve = require('koa-static');
const request = require("co-request");
var parse = require('co-body');
var koa = require('koa');
var app = koa();

app.use(logger());

const debug = console.log.bind(console);

app.use(serve(__dirname + '/Logbook'));

var api = new router({});

api.all('*', function*(next) {
  yield next;
  this.set('Access-Control-Allow-Methods', 'GET');
  this.set('Access-Control-Allow-Origin', '*');
  this.set('Access-Control-Allow-Headers', 'Content-type');
});

api.get('/user/overview', function*(){
  this.body = {
    "data": {
        "created_at": "2015-11-24T11:16:17.872Z",
        "department": "通用计算业务部/应用部",
        "id": "565447014919550001c127c9",
        "name": "wangkechun",
        "real_name": "\b王克纯",
        "updated_at": "2015-12-21T14:38:11.105Z"
    }
};
});

api.get('/departments', function*(){
  this.body = {
    "data": [
        "技术部门",
        "产品部门",
        "UED",
        "人事部门",
    ]
};
});


api.get('/users', function*(){
  this.body = {
    "data": [
        {
            "created_at": "2015-11-24T09:23:55.177Z",
            "department": "技术部门",
            "id": "u1",
            "name": "lihong",
            "real_name": "李红",
            "updated_at": "2015-11-25T07:32:54.406Z"
        },
        {
            "created_at": "2015-11-24T09:23:55.177Z",
            "department": "技术部门",
            "id": "u2",
            "name": "wangliang",
            "real_name": "王亮",
            "updated_at": "2015-11-25T07:32:54.406Z"
        },
        {
            "created_at": "2015-11-24T09:23:55.177Z",
            "department": "产品部门",
            "id": "u3",
            "name": "zhangming",
            "real_name": "张明",
            "updated_at": "2015-11-25T07:32:54.406Z"
        },
        {
            "created_at": "2015-11-24T09:23:55.177Z",
            "department": "UED",
            "id": "u4",
            "name": "liwei",
            "real_name": "李伟",
            "updated_at": "2015-11-25T07:32:54.406Z"
        },
        {
            "created_at": "2015-11-24T09:23:55.177Z",
            "department": "人事部门",
            "id": "u5",
            "name": "liming",
            "real_name": "李明",
            "updated_at": "2015-11-25T07:32:54.406Z"
        }
      ]
    }
});

api.get('/posts', function*(){
  console.log(this.request.query);
  const text = ` 但不仅仅是前端工程师。我们希望遇到这样的你：基础扎实，框架、组件都能砌；
创新，有想法，造的一手好轮子，但不纠结于必须造轮子；
思路不局限于前端，看到的是整个应用，乃至整个产品；
如果恰好还打算搞搞node（加分）
如果对数据应用感兴趣（加分）
如果对数据挖掘、算法感兴趣（加分）
整个应用的开发、数据分析、算法 ， 这几个加分项基本上会是未来几年创业技能必备。
在行业垂直化初步完成之后，这些技能将会让你和项目更具竞争力。
如果刚好你也有兴趣，不妨在这个低潮冬天，来和我们一起练练内力。
如果你符合以下几项要求，就可以加入我们：喜欢赛车并有 C1D 驾照
喜欢跑步并完成过一次全程马拉松
喜欢玩 TVGAME 并且取得「血源」白金的
使用机械键盘，并且赞同青轴的啪啪啪是最美妙的声音
如果以上都不符合，那就只能看看下面的要求了：两年以上开发经验，精通各种 Web 前端技术（ HTML/CSS/Javascript 等)；
熟练跨浏览器、跨终端的开发，有 HTML5/CSS3 等移动端 Web 页面开发经验和案例；
深刻理解 Web 标准，对可用性、可访问性有实际的了解和实践经验；
具备前端工程化的思维和实践经验；
技术视野广阔，有主导前端技术方案设计的能力和经验，能够独立承担项目开发工作；
良好的团队合作精神和积极主动的沟通意识，具有很强的学习能力和对新技术的追求精神，乐于分享；
有大型网站开发经验者优先。
工作地点：杭州西溪园区或深圳欢迎投递简历过来：fei.xf#alibaba-inc.com，投递时请注明【社招】或【校招】 `.split('\n');
  const r = function(){
    return text[Math.round(Math.random()*text.length-2)]
  };
  this.body = {
    "data": [
        {
            "content": r(),
            "created_at": "2015-11-25T07:35:24.095Z",
            "day": "2016-03-01",
            "id": "565564bc331ae10001060458",
            "mood": "grinning",
            "updated_at": "2015-11-25T07:35:24.095Z",
            "user_id": "u5"
        },
        {
            "content": r(),
            "created_at": "2015-11-25T07:35:24.095Z",
            "day": "2016-03-01",
            "id": "565564bc331ae10001061458",
            "mood": "grinning",
            "updated_at": "2015-11-25T07:35:24.095Z",
            "user_id": "u5"
        },
        {
            "content": r(),
            "created_at": "2015-11-25T07:35:24.095Z",
            "day": "2016-03-01",
            "id": "565564bc331ae10001060459",
            "mood": "grinning",
            "updated_at": "2015-11-25T07:35:24.095Z",
            "user_id": "u2"
        },
        {
            "content": r(),
            "created_at": "2015-11-25T07:35:24.095Z",
            "day": "2016-03-01",
            "id": "565564bc331ae100010604339",
            "mood": "grinning",
            "updated_at": "2015-11-25T07:35:24.095Z",
            "user_id": "u1"
        },
        {
            "content": r(),
            "created_at": "2015-11-25T07:35:24.095Z",
            "day": "2016-03-01",
            "id": "565564bc331ae10001060468",
            "mood": "grinning",
            "updated_at": "2015-11-25T07:35:24.095Z",
            "user_id": "u3"
        },
        {
            "content": r(),
            "created_at": "2015-11-25T07:35:24.095Z",
            "day": "2016-03-01",
            "id": "565564bc331ae10001060478",
            "mood": "grinning",
            "updated_at": "2015-11-25T07:35:24.095Z",
            "user_id": "u4"
        },
    ]
};
})

app.use(api.routes()).use(api.allowedMethods());

app.listen(9999);
console.log('listening on port 9999');
